package com.threegold.listviewsample.provider;

import com.threegold.listview.ListItemProvider;
import com.threegold.listview.ListView;
import com.threegold.listviewsample.ResourceTable;
import ohos.agp.components.Component;
import ohos.agp.components.ComponentContainer;
import ohos.agp.components.LayoutScatter;
import ohos.agp.components.Text;
import ohos.app.Context;

public class CommonListItemProvider extends ListItemProvider<String, ListView.ViewHolder> {

    LayoutScatter layoutScatter;

    public CommonListItemProvider(Context context) {
        layoutScatter = LayoutScatter.getInstance(context);
    }

    @Override
    protected ListView.ViewHolder onCreateViewHolder(ComponentContainer parent, int itemViewType) {
        Component item = layoutScatter.parse(ResourceTable.Layout_list_item, parent, false);
        return new ListView.ViewHolder(item, itemViewType);
    }

    @Override
    protected void onBindViewHolder(ListView.ViewHolder viewHolder, int position, String data, int itemWidth) {
        Text text = (Text) viewHolder.getViewById(ResourceTable.Id_text);
        text.setText(data);
    }

}
